/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            productLabelManageInfo: {
                productLabels: [],
                labels: [],
                total: 0,
                records: 1,
                moreCondition: false,
                productLabelId: '',
                conditions: {
                    prodName: '',
                    labelCd: '',
                    productId: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that.productLabelManageInfo.conditions.productId = vc.getParam('productId');
            $that._listLabels();
            $that._listProductLabels(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('productLabelManage', 'listLabel', function (_param) {
                $that._listProductLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listProductLabels(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listProductLabels: function (_page, _rows) {
                $that.productLabelManageInfo.conditions.page = _page;
                $that.productLabelManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.productLabelManageInfo.conditions
                };
                param.params.productId = param.params.productId.trim();
                param.params.prodName = param.params.prodName.trim();
                //发送get请求
                vc.http.apiGet('/product.queryProductLabel',
                    param,
                    function (json, res) {
                        var _productLabelManageInfo = JSON.parse(json);
                        $that.productLabelManageInfo.total = _productLabelManageInfo.total;
                        $that.productLabelManageInfo.records = _productLabelManageInfo.records;
                        $that.productLabelManageInfo.productLabels = _productLabelManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.productLabelManageInfo.records,
                            dataCount: $that.productLabelManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddLabelModal: function () {
                vc.emit('addLabel', 'openAddLabelModal', {});
            },
            _openDeleteLabelModel: function (_productLabel) {
                vc.emit('deleteProductLabel', 'openDeleteProductLabelModal', _productLabel);
            },
            //查询
            _queryLabelMethod: function () {
                $that._listProductLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetLabelMethod: function () {
                $that.productLabelManageInfo.conditions.labelCd = "";
                $that.productLabelManageInfo.conditions.productId = "";
                $that.productLabelManageInfo.conditions.prodName = "";
                $that._listProductLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.productLabelManageInfo.moreCondition) {
                    $that.productLabelManageInfo.moreCondition = false;
                } else {
                    $that.productLabelManageInfo.moreCondition = true;
                }
            },
            _listLabels: function () {
                var param = {
                    params: {
                        page: 1,
                        row: 100,
                        shopId: vc.getCurrentCommunity().shopId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/label/queryLabel',
                    param,
                    function (json, res) {
                        let _labelManageInfo = JSON.parse(json);
                        $that.productLabelManageInfo.labels = _labelManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            }
        }
    });
})(window.vc);
